package com.yc.jpyy.mobile.controller;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.TeacherDao;
import com.yc.jpyy.mobile.service.TeacherService;

@Controller
@RequestMapping(value = "/teacher")
public class GetTeacherSystemReportController extends BaseController {

	@Autowired
	private TeacherService teacherService;

	@Autowired
	private TeacherDao teacherDao;
	private static Logger logger = LoggerFactory.getLogger(GetTeacherSystemReportController.class);
	
	/**
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getSysReport", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getSysReport(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();

		try {
			String PageNum = request.getParameter("PageNum");
			String PageSize = request.getParameter("PageSize");

			if (PageNum != null && !PageNum.isEmpty() || PageSize != null
					&& !PageSize.isEmpty()) {
				if (PageNum.equals("0") || PageSize.equals("0")) {
					response.setErrorcode(1);
					response.setMessage("页码或页数不能为0...");
					return response.toJSON();
				}
			}
			String driveSchoolId=request.getParameter("driveSchoolId");
			if((null != driveSchoolId && !driveSchoolId.isEmpty()))
			{   
				Map<String,Object> paramsMap = new HashMap<>();
				paramsMap.put("PageNum", PageNum);
				paramsMap.put("PageSize", PageSize);
				paramsMap.put("driveSchoolId", driveSchoolId);
				//查询公告信息
				response = teacherService.getNews(paramsMap,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("驾校ID不能为空！");
			}
		} catch (Exception e) {
			logger.info("获取驾校通知信息："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("获取驾校通知信息失败!");
		} finally {
			return response.toJSON();
		}

	}

}
